package com.rerun.common.bean;

import com.rerun.common.util.StringUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * redis key 生成器.
 *
 * @author dax.
 * @version v1.0
 * @since 2017 /10/17 12:08
 */
public class RedisKey {
    private String  key;


    private RedisKey(String key) {
         this.key=key;
    }

    /**
     * The type Generator.
     */
    public static class Generator{
        private List<String>  tableNames;


        /**
         * Table name generator.
         *
         * @param tableName the table name
         * @return the generator
         */
        public Generator  tableName(String tableName){
               if (tableNames==null){
                 tableNames=new ArrayList<>();
               }
               tableNames.add(tableName);
            return this;
        }



        /**
         * Builder redis key.
         *
         * @return the redis key
         */
        public RedisKey builder(){
          String tabStr=  StringUtil.listToStr(tableNames,'_');
          if (tabStr!=null){
              return new RedisKey(tabStr);
          }
           throw new RuntimeException("id 生成不符合规则");
        }


    }

    public String Key() {
        return key;
    }

}
